from twisted.spread import pb
from twisted.internet import reactor
from twisted.python import util

def printData(d):
	print d

class loginAPI():
	def __init__(self):
		factory = pb.PBClientFactory()
		reactor.connectTCP('127.0.0.1', 8003, factory)
		self.d = factory.getRootObject()
		self.data = {}
		self.data['uid'] = 10002;
		self.data['pic'] = 'http://www.baidu.com/json.php?hello'

	def login(self, packet):
		ret = self.d.addCallback(lambda object: object.callRemote("logout", self.data))
		ret.addCallback(printData)

	def run(self):
		reactor.run()

c = loginAPI()
c.login("hello")
c.run()
#print "Client Go..."
#d.addCallback(lambda object: object.callRemote("echo", "hi"))
#print "Client call finished"


#d.addCallback(lambda result: result)
#d.addErrback(lambda reason: 'error: ' + str(reason.value))
#d.addCallback(util.println)
#d.addCallback(lambda _: reactor.stop())
#reactor.run()